package cn.wuxing.mediation.web.controller.system;

import cn.wuxing.mediation.common.core.controller.BaseController;
import cn.wuxing.mediation.common.core.domain.AjaxResult;
import cn.wuxing.mediation.system.domain.vo.QuickEntryVo;
import cn.wuxing.mediation.system.service.ISIndexService;
import cn.wuxing.mediation.system.service.ISMSGNotificationsService;
import cn.wuxing.mediation.system.service.ISTownshipCenterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mediation/index")
public class IndexController extends BaseController {

    @Resource
    private ISIndexService indexService;

    @Resource
    private ISMSGNotificationsService notificationsService;

    @Resource
    private ISTownshipCenterService townshipCenterService;

    @GetMapping("/townshipCenter")
    @ApiOperation(value = "", notes = "")
    private AjaxResult getTownshipCenter(@RequestParam(value = "townshipName", defaultValue = "") String townshipName) {
        List<Object> allArea = townshipCenterService.getTownshipCenterAll(townshipName);
        return AjaxResult.success(allArea);
    }

    @GetMapping("/area")
    @ApiOperation(value = "", notes = "")
    private AjaxResult getAllArea() {
        List<Object> allArea = indexService.getAllArea();
        return AjaxResult.success(allArea);
    }

    @GetMapping("/areaName")
    @ApiOperation(value = "", notes = "")
    private AjaxResult getAreaByName(@RequestParam("areaName")String areaName) {
        Map<String,Object> area = indexService.getAreaByName(areaName);
        return AjaxResult.success(area);
    }

    /**
     * 矛盾纠纷总览  情况总览  纠纷类型统计  纠纷区域分布统计
     *
     * @return
     */
    @GetMapping("/disputeAll")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeOverview(@RequestParam(value = "startTime", defaultValue = "") String startTime,
                                      @RequestParam(value = "endTime", defaultValue = "") String endTime) {
        List<Object> dataResult = indexService.disputeOverviewAll(startTime, endTime);
        return AjaxResult.success(dataResult);
    }

    /**
     * 纠纷主体分布
     *
     * @return
     */
    @GetMapping("/disputeSubject")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeSubjectDistribution(@RequestParam("startTime")String startTime,
                                                 @RequestParam("endTime")String endTime) {
        if (startTime == null||startTime.equals("undefined")) {
            startTime = "";
        }
        if (endTime == null||endTime.equals("undefined")) {
            endTime = "";
        }
        Map<String, Object> date = indexService.disputeSubjectDistribution(startTime,endTime);
        return AjaxResult.success(date);
    }

    /**
     * 纠纷趋势7天分布
     *
     * @return
     */
    @GetMapping("/disputeTrend")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeTrend(@RequestParam(value = "startTime", defaultValue = "") String startTime,
                                   @RequestParam(value = "endTime", defaultValue = "") String endTime) {
        if (startTime == null||startTime.equals("undefined")) {
            startTime = "";
        }
        if (endTime == null||endTime.equals("undefined")) {
            endTime = "";
        }
        Map<String, Long> date = indexService.disputeTrend(endTime);
        return AjaxResult.success(date);
    }

    /**
     * 个人工作情况-综窗 综合
     */
    @GetMapping("/disputeSynthesis")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeSynthesis(@RequestParam(value = "startTime", defaultValue = "") String startTime,
                                       @RequestParam(value = "endTime", defaultValue = "") String endTime) {
        if (startTime == null||startTime.equals("undefined")) {
            startTime = "";
        }
        if (endTime == null||endTime.equals("undefined")) {
            endTime = "";
        }

        List<Object> data = indexService.disputeSynthesis(startTime, endTime);
        return AjaxResult.success(data);
    }

    /**
     * 个人工作情况-专窗
     */
    @GetMapping("/disputeWindow")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeWindow(@RequestParam(value = "startTime", defaultValue = "") String startTime,
                                    @RequestParam(value = "endTime", defaultValue = "") String endTime) {
        if (startTime == null||startTime.equals("undefined")) {
            startTime = "";
        }
        if (endTime == null||endTime.equals("undefined")) {
            endTime = "";
        }
        List<Object> data = indexService.disputeWindow(startTime, endTime);
        return AjaxResult.success(data);
    }

    /**
     * 个人工作情况-调解员
     */
    @GetMapping("/disputeMediator")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeMediator(@RequestParam(value = "startTime", defaultValue = "") String startTime,
                                      @RequestParam(value = "endTime", defaultValue = "") String endTime) {
        if (startTime == null||startTime.equals("undefined")) {
            startTime = "";
        }
        if (endTime == null||endTime.equals("undefined")) {
            endTime = "";
        }

        List<Object> data = indexService.disputeMediator(startTime, endTime);
        return AjaxResult.success(data);
    }

    /**
     * 消息通知  Message notifications
     */
    @GetMapping("/disputeNotice")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeNotice() {
        List<Object> data=notificationsService.disputeNotice();
        return AjaxResult.success(data);
    }

    /**
     * 消息已读
     * @return
     */
    @GetMapping("/disputeNoticeRead")
    @ApiOperation(value = "", notes = "")
    public AjaxResult disputeNoticeRead(@RequestParam("noticeId")Long noticeId) {
        int result=notificationsService.disputeNoticeRead(noticeId);
        return AjaxResult.success(result);
    }

    /**
     * 快捷入口
     */
    @GetMapping("/quickEntryAll")
    public AjaxResult quickEntryAll(){
        List<QuickEntryVo> data=indexService.quickEntryAll();
        return AjaxResult.success(data);
    }
    @GetMapping("/quickEntry")
    public AjaxResult quickEntry(){
        List<QuickEntryVo> data=indexService.quickEntry();
        return AjaxResult.success(data);
    }
    @GetMapping("/quickEntrySave")
    public AjaxResult quickEntrySave(@RequestParam("ids")Long[] ids){
        Integer result=indexService.quickEntrySave(ids);
        return AjaxResult.success(result);
    }

}
